package com.mhg.thread;

/**
 * 测试join方法
 */
public class JoinThread extends Thread {
    //重写run方法
    @Override
    public void run() {
        try {
            int time = 5000;
            System.out.println("当前时间，子线程正在执行...");
            Thread.sleep(time);
            System.out.println("子线程执行完毕！");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    /**
     * 入口函数
     * @param args
     * @throws InterruptedException
     */
    public static void main(String[] args) throws InterruptedException {
        JoinThread myThread1 = new JoinThread();
        System.out.println("当前时间，主线程正在执行...");
        myThread1.start();
        //线程myThread1加入主线程
        myThread1.join();
        System.out.println("主线程执行完毕！");

    }

}
